package org.xi.behavioral.memento;

public class TextEditor {
    private String content;
    private EditorMemento memento;

    public void type(String text) {
        content += text;
        // 每次打字后创建一个新的备忘录
        memento = new EditorMemento(new EditorState(content));
    }

    public void undo() {
        if (memento != null) {
            content = memento.getState().getContent();
        }
    }

    public String getContent() {
        return content;
    }
}